/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.fd.controller;

import java.util.Collection;
import java.util.List;

import com.xy.biz.fd.domain.req.documentAttachment.ListDocumentAttachmentRequest;
import com.xy.biz.fd.domain.req.documentAttachment.SaveDocumentAttachmentRequest;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xy.lang.domain.Page;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.SaveChecks;
import com.xy.lang.validation.UpdateChecks;
import com.xy.lang.validation.annotation.Validatable;

import com.xy.biz.fd.domain.resp.GetDocumentAttachmentResponse;
import com.xy.biz.fd.domain.req.documentAttachment.GetDocumentAttachmentRequest;
import com.xy.biz.fd.domain.query.DocumentAttachmentQuery;
import com.xy.biz.fd.domain.converter.DocumentAttachmentConverter;
import com.xy.biz.fd.client.DocumentAttachmentClient;
import com.xy.biz.fd.service.DocumentAttachmentService;

/**
 *
 *
 * @author wcs
 * @date 2021-2-19
 */
@Deprecated
@Api(tags = "上传附件")
@Slf4j
@RestController
@RequestMapping("/api/fd/document_attachment")
public class DocumentAttachmentController implements DocumentAttachmentClient {

	@Autowired
	private DocumentAttachmentService documentAttachmentService;

	@Validatable(groups = {SaveChecks.class})
	@PostMapping(value = "/save")
	public Result<?> saveDocumentAttachment(@RequestBody SaveDocumentAttachmentRequest request) {
		documentAttachmentService.saveDocumentAttachment(DocumentAttachmentConverter.toBO(request));
		return Result.success();
	}

//	@Validatable(groups = {SaveChecks.class})
//	@PostMapping(value = "/save_all")
//	public Result<?> saveAllDocumentAttachment(@RequestBody Collection<SaveDocumentAttachmentRequest> collection) {
//		documentAttachmentService.saveAllDocumentAttachment(DocumentAttachmentConverter.toBO(collection));
//		return Result.success();
//	}

//	@Validatable(groups = {UpdateChecks.class})
//	@PostMapping(value = "/update")
//	public Result<?> updateDocumentAttachment(@RequestBody SaveDocumentAttachmentRequest request) {
//		documentAttachmentService.updateDocumentAttachment(DocumentAttachmentConverter.toBO(request));
//		return Result.success();
//	}

	@Validatable
	@PostMapping(value = "/delete")
	public Result<?> deleteDocumentAttachment(@RequestBody GetDocumentAttachmentRequest request) {
		documentAttachmentService.deleteDocumentAttachment(request.getDocumentAttachmentId());
		return Result.success();
	}

	@Validatable
	@PostMapping(value = "/get")
	@Override
	public Result<GetDocumentAttachmentResponse> getDocumentAttachment(@RequestBody GetDocumentAttachmentRequest request) {
		return Result.success(DocumentAttachmentConverter.toResponse(documentAttachmentService.getDocumentAttachment(request.getDocumentAttachmentId())));
	}

//	@PostMapping(value = "/list_by_ids")
//	@Override
//	public Result<List<GetDocumentAttachmentResponse>> listDocumentAttachmentById(@RequestBody Collection<Long> collection) {
//		return Result.success(DocumentAttachmentConverter.toResponse(documentAttachmentService.listDocumentAttachmentById(collection)));
//	}
//
//	@PostMapping(value = "/list")
//	@Override
//	public Result<List<GetDocumentAttachmentResponse>> listDocumentAttachment(@RequestBody ListDocumentAttachmentRequest request) {
//		return Result.success(DocumentAttachmentConverter.toResponse(documentAttachmentService.listDocumentAttachment(DocumentAttachmentConverter.toQuery(request))));
//	}

//	@PostMapping(value = "/count")
//	@Override
//	public Result<Integer> countDocumentAttachment(@RequestBody ListDocumentAttachmentRequest request) {
//		return Result.success(documentAttachmentService.countDocumentAttachment(DocumentAttachmentConverter.toQuery(request)));
//	}

//	@PostMapping(value = "/page")
//	@Override
//	public Result<Page<GetDocumentAttachmentResponse>> pageDocumentAttachment(@RequestBody ListDocumentAttachmentRequest request) {
//		DocumentAttachmentQuery query = DocumentAttachmentConverter.toQuery(request);
//		List<GetDocumentAttachmentResponse> list = DocumentAttachmentConverter.toResponse(documentAttachmentService.listDocumentAttachment(query));
//		int count = documentAttachmentService.countDocumentAttachment(query);
//		return Result.success(new Page<>(list, count));
//	}

}
